package com.zdp.auth.service;

import com.zdp.auth.LoginBody;
import com.zdp.auth.LoginVo;
import com.zdp.pojo.RemoteClientVo;
import com.zdp.utils.SpringUtils;

public interface IAuthStrategy {

    String BASE_NAME = "AuthStrategy";

    static LoginVo login(LoginBody loginBody, RemoteClientVo client) {
        // 授权类型和客户端id
        String clientId = loginBody.getClientId();
        String grantType = loginBody.getGrantType();
        String beanName = grantType + BASE_NAME;
        if (!SpringUtils.containsBean(beanName)) {
            throw new RuntimeException("授权类型不正确!");
        }
        IAuthStrategy instance = SpringUtils.getBean(beanName);
        instance.validate(loginBody);
        return instance.login(clientId, loginBody, client);
    }

    /**
     * 参数校验
     */
    void validate(LoginBody loginBody);

    /**
     * 登录
     */
    LoginVo login(String clientId, LoginBody loginBody, RemoteClientVo client);
}
